package guoanmaker.operator.business.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import guoanmaker.operator.business.dao.OperatorProviderOrderDao;
import guoanmaker.operator.business.model.OperatorRefuseRecord;
import guoanmaker.operator.business.model.OperatorSendMesToCus;
import guoanmaker.operator.business.model.OperatorUser;
import guoanmaker.operator.business.model.PersonalUser;
import guoanmaker.operator.business.model.ProvideOrderForm;
import guoanmaker.operator.business.model.ReturnResult;
import guoanmaker.operator.business.modelnobind.CouponAmount;
import guoanmaker.operator.business.modelnobind.GuzhuInfo;
import guoanmaker.operator.business.modelnobind.OderFormRo;
import guoanmaker.operator.business.modelnobind.ProvideOrderFormForOrder;
import guoanmaker.operator.business.repository.OperatorCouponsRepository;
import guoanmaker.operator.business.repository.OperatorRefuseRecordRepository;
import guoanmaker.operator.business.repository.OperatorSendMesToCusRepositoy;
import guoanmaker.operator.business.repository.OperatorUserRepository;
import guoanmaker.operator.business.repository.PersonalUserCouponRepository;
import guoanmaker.operator.business.repository.PersonalUserRepository;
import guoanmaker.operator.business.repository.ProvideCommodityRepository;
import guoanmaker.operator.business.repository.ProvideOrderFormRepository;
import guoanmaker.operator.business.repository.ProviderBusinessRepository;

@Service
public class OperatorOrderService {
	
	@Autowired
	private ProvideOrderFormRepository  provideOrderFormRepository;
	
	@Autowired
	private OperatorProviderOrderDao  operatorProviderOrderDao;
	
	@Autowired
	private ProvideCommodityRepository  provideCommodityRepository;
	
	@Autowired
	private  OperatorRefuseRecordRepository  operatorRefuseRecordRepository;
	
	@Autowired
	private PersonalUserRepository  personalUserRepository;
	
	
	@Autowired
	private ProviderBusinessRepository providerBusinessRepository;
	
	@Autowired
	private OperatorUserRepository   operatorUserRepository;
	
	@Autowired  
	private  HttpServletRequest request;
	@Autowired
	private OperatorCouponsRepository  operatorCouponsRepository;
	
	@Autowired
	private  PersonalUserCouponRepository  personalUserCouponRepository;
	@Autowired
	private OperatorSendMesToCusRepositoy operatorSendMesToCusRepositoy;
	@Autowired
	private OperatorSendCodeService operatorSendCodeService;
	

	
	@PersistenceContext
	private EntityManager manager;
	
	/**
	 * 
	 * @param page
	 * @param size
	 * @param status 订单状态1待支付  2待接单  3服务中  4待确认   5退款处理中(用户发起退款)   6已完成   7已关闭  8退款完成  9退款处理中(商家已拒绝退款)
	 * @return
	 */
	public Map<String, Object>  selectOrderInfos(Integer  page,Integer size,String status){
	
		return operatorProviderOrderDao.findByProperties(page, size, status);
	}
	
	
	public   Map<String, Object>     queryOrderInfos(Integer  page,Integer size,String status,String serverName,String  startOrderTime,
            String endOrderTime,String startOrderAmount,String endOrderAmount,String companyName,String orderNum,String userid,String couponid,String busid){
		
		return  operatorProviderOrderDao.queryOrderInfos(page, size, status, serverName, startOrderTime, endOrderTime, startOrderAmount, endOrderAmount, companyName, orderNum,userid,couponid,busid);
	}
	public   Map<String, Object>     querymiaoOrderInfos(String id){
		
		return  operatorProviderOrderDao.querymiaoOrderInfos(id);
	}
	
	
	public Workbook   exportOrderInfo(String  ids,String status){
		Workbook wb = new HSSFWorkbook();
	
		Sheet sheet = wb.createSheet();
		wb.setSheetName(0, "订单信息");
		Row header = sheet.createRow(0);
		header.createCell(0).setCellValue("订单号");	
		header.createCell(1).setCellValue("商品名称");	
		header.createCell(2).setCellValue("种类");	
		header.createCell(3).setCellValue("价格");	
		header.createCell(4).setCellValue("优惠券");	
		header.createCell(5).setCellValue("雇主");	
		header.createCell(6).setCellValue("下单时间");	
		header.createCell(7).setCellValue("状态");	
		header.createCell(8).setCellValue("服务商");	
		header.createCell(9).setCellValue("发票");	
		 String[]  pids=ids.split(",");
		 List<OderFormRo>   list= operatorProviderOrderDao.queryOrderInfosNoPage(status);
		 OderFormRo oderFormRo=new OderFormRo();
		 for (int i = 0; i < list.size(); i++) {
			 oderFormRo=list.get(i);
			 for (int j = 0; j< pids.length; j++) {
				 String id=pids[j];
				if(oderFormRo.getId().equals(id)){
					Row dataRow = sheet.createRow(sheet.getLastRowNum() + 1);
					dataRow.createCell(0).setCellValue(oderFormRo.getOrderNumber()!=null?oderFormRo.getOrderNumber():"");
					dataRow.createCell(1).setCellValue(oderFormRo.getCommodityName()!=null?oderFormRo.getCommodityName():"");
					dataRow.createCell(2).setCellValue(oderFormRo.getServerName()!=null?oderFormRo.getServerName():"");
					dataRow.createCell(3).setCellValue(oderFormRo.getUnitPrice()!=null?oderFormRo.getUnitPrice():0);
					dataRow.createCell(4).setCellValue(oderFormRo.getCoupons()!=null?oderFormRo.getCoupons():"");
					dataRow.createCell(5).setCellValue(oderFormRo.getName()!=null?oderFormRo.getName():"");
					dataRow.createCell(6).setCellValue(oderFormRo.getPlaceOrderTime()!=null?oderFormRo.getPlaceOrderTime():null);
					dataRow.createCell(7).setCellValue(oderFormRo.getOrderStatus()!=null?oderFormRo.getOrderStatus():"");
					dataRow.createCell(8).setCellValue(oderFormRo.getBusinessName()!=null?oderFormRo.getBusinessName():"");
					if(oderFormRo.getInvoiceState()!=null){
						if(oderFormRo.getInvoiceState().equals("0")){
							dataRow.createCell(9).setCellValue("未开");
						}else if(oderFormRo.getInvoiceState().equals("1")){
							dataRow.createCell(9).setCellValue("已开");
						}
					}else{
						dataRow.createCell(9).setCellValue("");
					}
					
				}
			 }
		}
		return wb;
	}
	//全部导出订单
	public Workbook   exportAllOrderInfo(){
		Workbook wb = new HSSFWorkbook();
	
		Sheet sheet = wb.createSheet();
		wb.setSheetName(0, "订单信息");
		Row header = sheet.createRow(0);
		header.createCell(0).setCellValue("订单编号");	
		header.createCell(1).setCellValue("商品名称");	
		header.createCell(2).setCellValue("种类");	
		header.createCell(3).setCellValue("金额");	
		header.createCell(4).setCellValue("优惠券");	
		header.createCell(5).setCellValue("雇主");	
		header.createCell(6).setCellValue("下单时间");	
		header.createCell(7).setCellValue("下单方式");	
		header.createCell(8).setCellValue("状态");	
		header.createCell(9).setCellValue("服务商");	
		header.createCell(10).setCellValue("发票");	
		header.createCell(11).setCellValue("佣金");	
		header.createCell(12).setCellValue("保证金");	
		header.createCell(13).setCellValue("银行手续费");	
		header.createCell(14).setCellValue("实付金额");	
		 List<OderFormRo>   list= operatorProviderOrderDao.queryOrderAllInfosNoPage();
		 OderFormRo oderFormRo=new OderFormRo();
		 for (int i = 0; i < list.size(); i++) {
			        oderFormRo=list.get(i);
					Row dataRow = sheet.createRow(sheet.getLastRowNum() + 1);
					dataRow.createCell(0).setCellValue(oderFormRo.getOrderNumber()!=null&&!oderFormRo.getOrderNumber().equals("")?oderFormRo.getOrderNumber():"");
					dataRow.createCell(1).setCellValue(oderFormRo.getCommodityName()!=null&&!oderFormRo.getCommodityName().equals("")?oderFormRo.getCommodityName():"");
					dataRow.createCell(2).setCellValue(oderFormRo.getServerName()!=null&&!oderFormRo.getServerName().equals("")?oderFormRo.getServerName():"");
					dataRow.createCell(3).setCellValue(oderFormRo.getTruePrice()!=null?oderFormRo.getTruePrice():0);
					if(oderFormRo.getPreferentialMoney()!=null){
						if(oderFormRo.getPreferentialMoney()>0){
							dataRow.createCell(4).setCellValue("减"+oderFormRo.getPreferentialMoney()+"元");
						}else{
							dataRow.createCell(4).setCellValue("");
						}
					}else{
						dataRow.createCell(4).setCellValue("");
					}
					dataRow.createCell(5).setCellValue(oderFormRo.getUsername()!=null?oderFormRo.getUsername():"");
					if(oderFormRo.getPlaceOrderTime()!=null&&!oderFormRo.getPlaceOrderTime().equals("")){
						SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ");
				    	String ss=	sdf.format(oderFormRo.getPlaceOrderTime()); 
						dataRow.createCell(6).setCellValue(ss);
					}else{
						dataRow.createCell(6).setCellValue("");
					}
					//下单方式  1为PC   2为APP
					if(oderFormRo.getPlaceOrderType()!=null&&!oderFormRo.getPlaceOrderType().equals("")){
						dataRow.createCell(7).setCellValue(oderFormRo.getPlaceOrderType().equals("1")?"PC":"App");
					}else{
						dataRow.createCell(7).setCellValue("");
					}
					//订单状态1待支付  2待接单  3服务中  4待确认   5退款处理中(用户发起退款)   6已完成(未评论)   7已关闭  8已关闭(退款完成)
					//9退款处理中(商家已拒绝退款)  10退款处理中(服务商接受退款并向财务发起退款,等待财务平台处理) 11退款处理中(服务商发起关闭订单,等待财务平台退款,退款完成变为12)
					//12已关闭(未接单发起的退款) 13已完成（已评论）  14议价商品待沟通  15已关闭（付款但未退款） 
					if(oderFormRo.getOrderStatus()!=null&&!oderFormRo.getOrderStatus().equals("")){
						if(oderFormRo.getOrderStatus().equals("1")){
							dataRow.createCell(8).setCellValue("待支付 ");	
						}else if(oderFormRo.getOrderStatus().equals("2")){
							dataRow.createCell(8).setCellValue("待接单 ");	
						}else if(oderFormRo.getOrderStatus().equals("3")){
							dataRow.createCell(8).setCellValue("服务中");	
						}else if(oderFormRo.getOrderStatus().equals("4")){
							dataRow.createCell(8).setCellValue("待确认");	
						}else if(oderFormRo.getOrderStatus().equals("5")||oderFormRo.getOrderStatus().equals("9")||oderFormRo.getOrderStatus().equals("10")){
							dataRow.createCell(8).setCellValue("退款处理中");	
						}else if(oderFormRo.getOrderStatus().equals("7")||oderFormRo.getOrderStatus().equals("8")||oderFormRo.getOrderStatus().equals("11")||
								oderFormRo.getOrderStatus().equals("12")||oderFormRo.getOrderStatus().equals("15")){
							dataRow.createCell(8).setCellValue("已关闭");	
						}else if(oderFormRo.getOrderStatus().equals("6")||oderFormRo.getOrderStatus().equals("13")){
							dataRow.createCell(8).setCellValue("已完成");	
						}else if(oderFormRo.getOrderStatus().equals("14")){
							dataRow.createCell(8).setCellValue("待沟通");	
						}
					}else {
						dataRow.createCell(8).setCellValue("");
					}
					dataRow.createCell(9).setCellValue(oderFormRo.getBusinessName()!=null&&!oderFormRo.getBusinessName().equals("")?oderFormRo.getBusinessName():"");
					if(oderFormRo.getInvoiceState()!=null){
						if(oderFormRo.getInvoiceState().equals("0")){
							dataRow.createCell(10).setCellValue("未申请");
						}else if(oderFormRo.getInvoiceState().equals("1")){
							dataRow.createCell(10).setCellValue("已申请");
						}
					}else{
						dataRow.createCell(10).setCellValue("未申请");
					}
					dataRow.createCell(11).setCellValue(oderFormRo.getCommission()!=null?oderFormRo.getCommission().doubleValue():0);
					dataRow.createCell(12).setCellValue(oderFormRo.getBail()!=null?oderFormRo.getBail().doubleValue():0);
					dataRow.createCell(13).setCellValue(oderFormRo.getFee()!=null?oderFormRo.getFee().doubleValue():0);
					//实付金额
					if(oderFormRo.getRealPrice()!=null){
						if(oderFormRo.getPreferentialMoney()!=null){
							Double a= oderFormRo.getRealPrice()-oderFormRo.getPreferentialMoney();
							if(a>0){
								dataRow.createCell(14).setCellValue(a);
							}else{
								dataRow.createCell(14).setCellValue(0);
							}
						}else{
							dataRow.createCell(14).setCellValue(oderFormRo.getRealPrice());
						}
					}else{
						dataRow.createCell(14).setCellValue(0);
						
					}
		}
		return wb;
	}
	
	
	
	
	
	public Workbook   exportmiaoOrderInfos(String id){
		Workbook wb = new HSSFWorkbook();
		
		Sheet sheet = wb.createSheet();
		Sheet sheet1 = wb.createSheet();
		wb.setSheetName(0, "下单人数");
		Row header = sheet.createRow(0);
		header.createCell(0).setCellValue("商品名称");	
		header.createCell(1).setCellValue("商品现价");	
		header.createCell(2).setCellValue("秒杀价格");	
		header.createCell(3).setCellValue("下单时间");	
		 List<OderFormRo>  list=	 operatorProviderOrderDao.exquerymiaoOrderInfos(id);
		 OderFormRo oderFormRo=null;
		for (int i = 0; i < list.size(); i++) {
			        oderFormRo=list.get(i);
					Row dataRow = sheet.createRow(sheet.getLastRowNum() + 1);
					dataRow.createCell(0).setCellValue(oderFormRo.getCommodityName()!=null?oderFormRo.getCommodityName():"");
					dataRow.createCell(1).setCellValue(oderFormRo.getTruePrice()!=null?oderFormRo.getTruePrice():0);
					dataRow.createCell(2).setCellValue(oderFormRo.getSpikePrice()!=null?oderFormRo.getSpikePrice():0);
					if(oderFormRo.getPlaceOrderTime()!=null&&!oderFormRo.getPlaceOrderTime().equals("")){
						SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ");
				    	String ss=	sdf.format(oderFormRo.getPlaceOrderTime()); 
						dataRow.createCell(3).setCellValue(ss);
					}else{
						dataRow.createCell(3).setCellValue("");
					}
					
		}
		wb.setSheetName(1, "支付人数");
		Row header1 = sheet1.createRow(0);
		header1.createCell(0).setCellValue("商品名称");	
		header1.createCell(1).setCellValue("商品现价");	
		header1.createCell(2).setCellValue("支付价钱");	
		header1.createCell(3).setCellValue("支付时间");	
		List<OderFormRo>  list1=	 operatorProviderOrderDao.exquerymiaoOrderInfoszhifu(id);
		 OderFormRo oderFormRo1=null;
		 for (int i = 0; i < list1.size(); i++) {
			 oderFormRo1=list1.get(i);
				Row dataRow = sheet1.createRow(sheet1.getLastRowNum() + 1);
				dataRow.createCell(0).setCellValue(oderFormRo1.getCommodityName()!=null?oderFormRo1.getCommodityName():"");
				dataRow.createCell(1).setCellValue(oderFormRo1.getTruePrice()!=null?oderFormRo1.getTruePrice():0);
				dataRow.createCell(2).setCellValue(oderFormRo1.getSpikePrice()!=null?oderFormRo1.getSpikePrice():0);
				if(oderFormRo1.getDefrayTime()!=null&&!oderFormRo1.getDefrayTime().equals("")){
					SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ");
					String ss=	sdf.format(oderFormRo1.getDefrayTime()); 
					dataRow.createCell(3).setCellValue(ss);
				}else{
					dataRow.createCell(3).setCellValue("");
				}
		}
		
		return wb;
	}
	
	
	
	@Transactional
	public  ReturnResult  closeSureOrder(String id,String refuseName,String content,Double refunds,String userid){
		    ReturnResult returnResult =new ReturnResult();
			OperatorRefuseRecord  operatorRefuseRecord=new OperatorRefuseRecord();
			if(content!=null&&!content.equals("")){
				ProvideOrderForm  provideOrderForm=	provideOrderFormRepository.findOne(id);
				if(provideOrderForm!=null){
					/*provideOrderForm.setOrderStatus("7");
					provideOrderFormRepository.save(provideOrderForm);*/
					operatorRefuseRecord.setAttributId(id);
					operatorRefuseRecord.setContent(content);
					operatorRefuseRecord.setReasonName(refuseName);
					operatorRefuseRecord.setRefuseTime(new Date());
					operatorRefuseRecord.setOpchannel(2);
					operatorRefuseRecord.setRefunds(refunds);
					operatorRefuseRecord.setStatus(4);
					OperatorUser op=operatorUserRepository.findOne(userid);
					if(op!=null){
						operatorRefuseRecord.setUseraccountforcord(op.getUsername()+"关闭");
					}
					operatorRefuseRecordRepository.save(operatorRefuseRecord);
					returnResult.setKey("success");
					returnResult.setValue("关闭成功");
				}else{
					returnResult.setKey("error");
					returnResult.setValue("关闭失败");
				}
			}else{
				returnResult.setKey("error");
				returnResult.setValue("内容不可为空");
			}
		return  returnResult;
	}
	
	public ProvideOrderFormForOrder findbyOrderId(String id){
		
		return operatorProviderOrderDao.findByid(id);
	}
	
	
	public  String selectCouponidForinfo(String couponid){
		String str="";
		if(couponid.contains(",")){
			String[] coupidSs = couponid.split(",");
			String pid="";
			for (int i = 0; i < coupidSs.length; i++) {
				pid=coupidSs[i];
				String sql = "SELECT s.fullamount,s.subamount,s.lapseamount FROM "+
						" t_personal_user u "+
					    " LEFT JOIN t_personal_user_coupon o ON o.user_id = u.id "+
					    " LEFT JOIN t_operator_coupons s ON s.id = o.oc_id "+
					    " where o.id ='" + pid + "' " ;
							Query query = manager.createNativeQuery(sql);
							List  objecArraytList = query.getResultList();
							for(int j=0;j<objecArraytList.size();j++) {     
								CouponAmount  userCoupon=new CouponAmount();
					            Object[] obj = (Object[]) objecArraytList.get(j);
					            userCoupon.setFullamount((Double) obj[0]);
					            userCoupon.setSubamount( (Double) obj[1]);
					            userCoupon.setLapseamount((Double)obj[2]);
					            if(userCoupon.getFullamount()!=null&&userCoupon.getSubamount()!=null){
					            	str+="满"+userCoupon.getFullamount()+"减"+userCoupon.getSubamount()+",";
					            }else{
					            	str+="直减"+userCoupon.getLapseamount()+",";
					            }
			       }
			
		
			}
		
        }else{
	        	String sql = "SELECT s.fullamount,s.subamount,s.lapseamount FROM "+
						" t_personal_user u "+
					    " LEFT JOIN t_personal_user_coupon o ON o.user_id = u.id "+
					    " LEFT JOIN t_operator_coupons s ON s.id = o.oc_id "+
					    " where o.id ='" + couponid + "' " ;
							Query query = manager.createNativeQuery(sql);
							List  objecArraytList = query.getResultList();
							for(int j=0;j<objecArraytList.size();j++) {     
								CouponAmount  userCoupon=new CouponAmount();
					            Object[] obj = (Object[]) objecArraytList.get(j);
					            userCoupon.setFullamount((Double) obj[0]);
					            userCoupon.setSubamount( (Double) obj[1]);
					            userCoupon.setLapseamount((Double)obj[2]);
					            if(userCoupon.getFullamount()!=null&&userCoupon.getSubamount()!=null){
					            	str="满"+userCoupon.getFullamount()+"减"+userCoupon.getSubamount();
					            }else{
					            	str="直减"+userCoupon.getLapseamount();
					            }
			          }
        }  
		return str;
	}
	
	
	//雇主详情
	public  GuzhuInfo  queryUserAndCompanyinfo(String userid){
		/*String jpql="select  new guoanmaker.operator.business.modelnobind.GuzhuInfo(u.username,u.name,u.email,u.wechat,b.companyName,"+
			         "b.companyindustry,b.companyRegistTime,b.companyRegisteredCapital, b.companyfrontDeskphone, b.companyEmail,"
			         + " b.companyEnterpriseScale) from  PersonalUser  u  left join b.personalUser u where 1=1";*/
		String sql="select  u.username,u.name,u.email,u.wechat,b.company_name,b.company_industry,b.company_regist_time,b.company_registered_capital,b.companyfront_deskphone,b.company_email,b.company_enterprise_scale  from t_personal_user u LEFT JOIN  t_provide_business  b  on b.personal_user_id=u.id  where  1=1";
		      sql+=" and u.id='" + userid + "' " ;
		      Query query = manager.createNativeQuery(sql);
			  List result = query.getResultList();
			  GuzhuInfo  guzhuInfo=new GuzhuInfo();
				for(int i=0;i<result.size();i++) {     
	        	  Object[] obj = (Object[]) result.get(i);
	        	  guzhuInfo.setUsername((String) obj[0]);
	        	  guzhuInfo.setName((String) obj[1]);
	        	  guzhuInfo.setEmail((String) obj[2]);
	        	  guzhuInfo.setWechat((String) obj[3]);
	        	  guzhuInfo.setCompanyName((String) obj[4]);
	        	  guzhuInfo.setCompanyindustry((String) obj[5]);
	        	  guzhuInfo.setCompanyRegistTime((Date) obj[6]);
	        	  guzhuInfo.setCompanyRegisteredCapital((String) obj[7]);
	        	  guzhuInfo.setCompanyfrontDeskphone((String) obj[8]);
	        	  guzhuInfo.setCompanyEmail((String) obj[9]);
	        	  guzhuInfo.setCompanyEnterpriseScale((String) obj[10]);
	          }
		return  guzhuInfo;
	}
	/**
	 * 下单进行推送
	 * @author lsy
	 * @param userid
	 * @param orderNumber
	 * @return
	 */
	public ReturnResult sendMessage(String userid) {
		String content13 = "尊敬的用户您的付款已成功，同时您将获得由国安创客优质服务商提供的企业服务体验包：<br/>"+
				"a.联想技术团队提供的钉钉认证部署服务<br/>"+
				"b.创业服务包（商标注册、作品著作权登记、二个月小规模代理记账任选一项）<br/>"+
				"国安创客将安排专属服务人员跟进您的订单，您也可以随时致电4008518585了解相关信息。";
		String content14 = "尊敬的用户您的付款已成功，同时您将获得由国安创客优质服务商提供的企业服务体验包：\n"+
				"a.联想技术团队提供的钉钉认证部署服务\n"+
				"b.创业服务包（商标注册、作品著作权登记、二个月小规模代理记账任选一项）\n"+
				"国安创客将安排专属服务人员跟进您的订单，您也可以随时致电4008518585了解相关信息。";
		ReturnResult returnResult = new ReturnResult();
		PersonalUser personalUser=personalUserRepository.findOne(userid);
		try{
			 OperatorSendMesToCus od=new OperatorSendMesToCus();
			 if(personalUser!= null && personalUser.getEmail()!=null){
			 od.setEmail(personalUser.getEmail());}
			 od.setPhone(personalUser.getUsername());
			 od.setSendWay("13");//站内信
			 od.setMesContent(content13);
			 od.setMesTitle("下单通知");
			 od.setSendTime(new Date());
			 od.setSendStatus("1");//1  未读  2已读
			 od.setMesType("19");//消息
			 operatorSendMesToCusRepositoy.save(od);
			}catch(Exception e){
				e.printStackTrace();
			}
		OperatorSendMesToCus od = new OperatorSendMesToCus();
		od.setEmail(personalUser.getEmail());
		od.setPhone(personalUser.getUsername());
		od.setSendWay("14");//短信
		od.setSendStatus("1");//1  未读  2已读
		od.setSendTime(new Date());
		od.setMesType("19");//消息
		od.setMesContent(content14);
		operatorSendMesToCusRepositoy.save(od);
		try {
			operatorSendCodeService.sendMessage(od.getPhone(), od.getMesContent());
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("短信消息发送失败");
		} 
		returnResult.setKey("success");
		returnResult.setValue("推送成功");
		return returnResult;
	}

}
